package weixinkeji.dev.dc.buy.order.h.manager;

import MyUI.ligerUI.bean.LigerUIOrderBy;
import MyUI.ligerUI.service.LigeruiService;
import com.alibaba.fastjson.JSON;
import sys.wx.ann.hm.M;
import sys.wx.c.ATR;
import sys.wx.c.components.check.bean.CheckData;
import sys.wx.c.components.cv.CV;
import sys.wx.m.db.SQL.mysql.common.orderby.OrderBy;
import sys.wx.m.db.SQL.mysql.common.where.Where;
import sys.wx.m.db.SQL.mysql.common.where.WhereConfig;
import sys.wx.m.db.dao.mysql.Dao;
import weixinkeji.dev.dc.buy.order.bean.FWYOrder;
import weixinkeji.dev.dc.buy.order.bean.FWYOrderB;
import weixinkeji.dev.dc.buy.order.xy.FWYOrderXY;

@sys.wx.ann.hm.H("view/buy/order/manager/fwy/s")

//身份类型授权。无需人工付权。
//代表 是服务员才能进行访问。
//@SQ(DCPower.ID_FWY)
public class ManagerFWYOrderS {

    public static final String ORDERBY = OrderBy.getOrderBy("order_id", "DESC");

    //查询未结账的单据。
    @M("/selectMJZ")//通过 view/buy/order/manager/fwy/s/selectMJZ.imy 访问
    public static String selectMJZ(ATR a) {
        Where x = new Where(new WhereConfig(""));
        x.put(Where.TJ_IGNORE_NOTHING, "", "order_sort", "=", FWYOrderXY.H_NOT_PAY_MONEY_ORDER);
        x.put(Where.TJ_IGNORE_NULL, Where.AND, "room_code", "=", CV.getParameter(a.request, "room_code", "[0-9]+"));
        String lr = CV.getParameter(a.request, "order_code", "[0-9]+");
        x.put(Where.TJ_IGNORE_NULL, Where.AND, "order_code", "LIKE", null == lr ? null : "%" + lr);

        LigerUIOrderBy ob = LigeruiService.getOrderBy(a.request);
        a.printOne(LigeruiService.getGRID_1_2(
                Dao.selectVastOrderBy(FWYOrder.class, x.getWhere(), null == ob.sortname ? ORDERBY : OrderBy.getOrderBy(ob.sortname, ob.sortorder)), 1));
        return null;
    }

    @M("/selectOne")//通过 view/buy/order/manager/fwy/s/selectOne.imy 访问
    public static String selectOne(ATR a) {
        String order_id = CV.getParameter(a.request, "order_id", CheckData.ID);
        if (null == order_id) {
            return null;
        }
        a.printOne(JSON.toJSONString(Dao.selectOneByID(FWYOrder.class, order_id)));
        return null;
    }

    @M("/selectOneB")//通过 view/buy/order/manager/fwy/s/selectOne.imy 访问
    public static String selectOneB(ATR a) {
        String order_id = CV.getParameter(a.request, "order_id", CheckData.ID);
        if (null == order_id) {
            return null;
        }
        Where w = new Where(new WhereConfig(""));
        w.put(Where.TJ_IGNORE_NOTHING, "", "order_id", "=", order_id)
                .put(Where.TJ_IGNORE_NOTHING, Where.AND, "orderb_style", "<>", "1");
 
        a.printOne(LigeruiService.getGRID(
                Dao.selectVast(FWYOrderB.class, w.getWhere())
        ));
        return null;
    }
}
